package org.extremecomponents.table.view.freemarker.extend;

import org.extremecomponents.table.core.TableModel;
import org.extremecomponents.table.view.html.BuilderUtils;
import org.extremecomponents.table.view.html.TableActions;

/**
 * @author Eccn-sshwsfc
 * 
 * only proxy some utils method easy use in view
 */
public class LimitExtend {
	
	private TableModel model;
	private int totalPages;
	private int page;

	public LimitExtend(TableModel model) {
		this.model = model;
		this.totalPages = getTotalPages();
		this.page = model.getLimit().getPage();
	}
	
    public boolean isFirstPageEnabled() {
    	return BuilderUtils.isFirstPageEnabled(page);
    }

    public boolean isPrevPageEnabled() {
    	return BuilderUtils.isPrevPageEnabled(page);
    }

    public boolean isNextPageEnabled() {
    	return BuilderUtils.isNextPageEnabled(page, totalPages);
    }

    public boolean isLastPageEnabled() {
    	return BuilderUtils.isLastPageEnabled(page, totalPages);
    }

    public int getTotalPages() {
    	return BuilderUtils.getTotalPages(model);
    }
    
    public String getFirstPageAction(){
    	return new TableActions(model).getPageAction(1);
    }
    
    public String getPrevPageAction(){
    	int page = model.getLimit().getPage();
    	return new TableActions(model).getPageAction(page - 1);
    }
    
    public String getNextPageAction(){
    	int page = model.getLimit().getPage();
    	return new TableActions(model).getPageAction(page + 1);    	
    }
    
    public String getLastPageAction(){
        int totalPages = BuilderUtils.getTotalPages(model);
        return new TableActions(model).getPageAction(totalPages);
    }
    
    public String getRowsDisplayedAction(){
    	return new TableActions(model).getRowsDisplayedAction();
    }
    
    public String getFilterAction(){
    	return new TableActions(model).getFilterAction();
    }
    
    public String getClearAction(){
    	return new TableActions(model).getClearAction();
    }
}
